﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Utils.States
{
    public static class Gc
    {
        /*
         * GuardCondition Altering Methods
         */
        public static Transition.GCMethod Not(Transition.GCMethod gc)
        {
            return new GcNot(gc).GcMethod;
        }

        public static Transition.GCMethodCtx Not(Transition.GCMethodCtx gc)
        {
            return new GcNotCtx(gc).GcMethod;
        }

        public static Transition.GCMethod And(Transition.GCMethod gcA, Transition.GCMethod gcB)
        {
            return new GcAnd(gcA, gcB).GcMethod;
        }

        /*
         * Helper Classes for the methods
         */
        class GcNot
        {
            Transition.GCMethod gc;

            public GcNot(Transition.GCMethod gc)
            {
                this.gc = gc;
            }

            public bool GcMethod()
            {
                return !gc();
            }
        }

        class GcNotCtx
        {
            Transition.GCMethodCtx gc;

            public GcNotCtx(Transition.GCMethodCtx gc)
            {
                this.gc = gc;
            }

            public bool GcMethod(StateMachineCtx ctx)
            {
                return !gc(ctx);
            }
        }

        class GcAnd
        {
            Transition.GCMethod gcA;
            Transition.GCMethod gcB;

            public GcAnd(Transition.GCMethod gcA, Transition.GCMethod gcB)
            {
                this.gcA = gcA;
                this.gcB = gcB;
            }

            public bool GcMethod()
            {
                return gcA() && gcB();
            }
        }
    }
}
